<template>
	<view class="choose-scene-page">
		<view class="item" v-for="item in list" :key="item.id" @click="sceneChange(item.id)">
			<image :src="baseUrl + item.img" mode="aspectFill"></image>
			<text>{{item.scene_title}}</text>
		</view>

		<!-- 弹窗 -->
		<u-popup v-model="show" mode="center" border-radius="10" :mask-close-able="false">
			<view class="pupop">
				<view class="t1">
					<text>请选择时段</text>
				</view>

				<view class="t2" :class="{'t2-act': typeIdx == idx}" v-for="(item, idx) in timeTypes" :key="item.id"
					@click="typeChange(idx)">
					<text>{{item.text}}</text>
					<u-icon v-if="typeIdx == idx" name="checkbox-mark" color="#3D99BB"></u-icon>
				</view>

				<view class="bottom">
					<view class="btn" @click="pupopCancle">
						<text>取消</text>
					</view>
					<view class="block"></view>
					<view class="btn" @click="pupopConfirm">
						<text>确认</text>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: this.$u.api.baseUrl,
				show: false,
				timeTypes: [{
					id: 1,
					text: '督导时段'
				}, {
					id: 2,
					text: '非督导时段'
				}],
				typeIdx: 0,
				oldIdx: 0,
				list: []
			};
		},
		onLoad() {
			const item = this.timeTypes[0]
			this.$u.vuex('vuex_evaluate.supervision_time', item.text)
		},
		onShow() {
			this.getList()
		},
		methods: {
			getList() {
				this.$u.post('/scenelist').then(res => {
					this.list = res.filter(v => {
						return v.status == 1
					})
					
					if(this.list.length == 0) {
						uni.showModal({
							showCancel: false,
							title: '提示',
							content: '暂无可用考评',
							success: () => {
								uni.navigateBack({
									delta: 1
								})
							}
						})
						
						return
					}
					
					this.show = true
				});
			},

			typeChange(idx) {
				this.typeIdx = idx
			},

			pupopCancle() {
				this.typeIdx = this.oldIdx
			},

			pupopConfirm() {
				this.oldIdx = this.typeIdx
				const item = this.timeTypes[this.typeIdx]
				this.$u.vuex('vuex_evaluate.supervision_time', item.text)
				this.show = false
			},

			sceneChange(id) {
				this.$u.vuex('vuex_evaluate.scene_id', id)
				uni.redirectTo({
					url: '/pagesA/evaluate/evaluate'
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	.choose-scene-page {
		padding: 30rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;

		.item {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-bottom: 28rpx;

			image {
				width: 330rpx;
				height: 226rpx;
			}

			text {
				margin-top: 18rpx;
				font-size: 32rpx;
				font-weight: bold;
				line-height: 44rpx;
				color: #131415;
			}
		}

		.pupop {
			position: relative;
			width: 574rpx;
			height: 400rpx;
			padding-top: 30rpx;
			background: #FFFFFF;
			text-align: center;

			.t1 {
				margin: 0 auto;
				font-size: 36rpx;
				font-weight: bold;
				line-height: 50rpx;
				color: #131415;
			}

			.t2 {
				margin-top: 38rpx;
				color: #999999;

				&-act {
					color: #3D99BB;
				}

				text {

					font-size: 32rpx;
					font-weight: 400;
					line-height: 44rpx;
				}

				u-icon {
					margin-left: 14rpx;
				}
			}

			.bottom {
				position: absolute;
				bottom: 0;
				left: 0;
				right: 0;
				height: 100rpx;
				border-top: 1rpx solid #F5F5F5;
				display: flex;

				.btn {
					flex: 1;
					display: flex;
					justify-content: center;
					align-items: center;

					text {
						font-size: 32rpx;
						font-weight: 400;
						line-height: 44rpx;
						color: #999999;
					}
				}

				.block {
					width: 1rpx;
					height: 98rpx;
					background-color: #F5F5F5;
				}
			}
		}

	}
</style>
